package java8;

import java8.entity.Employee;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class LambdaStreamSort {
    public static void main(String[] args) {

        Employee e1 = new Employee(1, 22, "F", "aa", "aa");
        Employee e2 = new Employee(2, 23, "M", "bb", "bb");
        Employee e3 = new Employee(3, 24, "F", "cc", "cc");
        Employee e4 = new Employee(4, 25, "M", "dd", "dd");
        Employee e5 = new Employee(5, 26, "M", "ee", "ee");
        Employee e6 = new Employee(6, 27, "F", "gg", "gg");

        List<Employee> employees = Arrays.asList(e1, e2, e3, e4, e5, e6);

        employees.sort(
                //排序器使用 gender 进行排序，并且是逆序
//                Comparator.comparing(Employee::getGender)
//                        .reversed()
//                        .thenComparingInt(Employee::getAge)
//                        .reversed()

                //这里如果想要使用 reversed() 函数必须对 comparing 的元素进行强转
                Comparator.comparing(e ->  ((Employee)e).getAge()).reversed().thenComparing(e -> ((Employee) e).getGender())
        );

//        employees.forEach(System.out::println);

        List<String> strArray = Arrays.asList("f", "a", "u", "o");

        //定义自然的排序规则
        strArray.sort(String.CASE_INSENSITIVE_ORDER);
        System.out.println(strArray);

        //使用排序器
        strArray.sort(Comparator.naturalOrder());
        System.out.println(strArray);

        List<Integer> array = Arrays.asList(5, 4, 3, 2);
        array.sort(Comparator.naturalOrder());
//        array.forEach(System.out::println);

//        Integer[] arr = (Integer[])array.toArray();
//        Arrays.sort(arr, Comparator.reverseOrder());
//        for(Integer e: arr) {
//            System.out.println(e);
//        }
    }
}
